//
//  RotationEffectView2.swift
//  SwiftUIAnimation
//
//  Created by 李煜 on 2024/8/20.
//

import SwiftUI

struct RotationEffectView2: View {
  @State private var isLoading = false
  var body: some View {
    ZStack {
      //添加一个进度条背景
      Circle()
        .stroke(Color(.systemGray5), lineWidth: 40)
        .frame(width: 200, height: 200)
      Circle()
        .trim(from: 0.0, to: 0.9)
        .stroke(Color.orange, lineWidth: 15)
        .frame(width: 200)
        .rotationEffect(.degrees(isLoading ? 360 : 0))
      //给动画添加时长
        .animation(.linear(duration: 10).repeatForever(autoreverses: false), value: isLoading)
        .onAppear {
          isLoading = true
        }
    }
  }
}

#Preview {
  RotationEffectView2()
}
